<?php

namespace App\Http\Controllers\Admin;

use App\Http\Controllers\BaseAdminController;
use App\Http\Requests\TrainingLevelHeadRequest;
use App\Models\QueryBuilder;
use App\Models\TrainingLevelHead;
use Illuminate\Http\Resources\Json\JsonResource;
use Spatie\QueryBuilder\AllowedFilter;

class TrainingLevelHeadController extends BaseAdminController
{
    //列表
    public function index()
    {
        $data = QueryBuilder::for(TrainingLevelHead::query())
            ->fields()
            ->filters([AllowedFilter::exact('training_level_id'), 'head_name'])
            ->includes('trainingLevel')
            ->sorts()
            ->page();
        return $this->success(JsonResource::collection($data));
    }

    //添加
    public function store(TrainingLevelHeadRequest $request)
    {
        TrainingLevelHead::query()->create($request->toArray());
        return $this->success();
    }

    //编辑
    public function update(TrainingLevelHead $traininglevelhead, TrainingLevelHeadRequest $request)
    {
        $traininglevelhead->update($request->toArray());
        return $this->success();
    }

    //删除
    public function destroy(TrainingLevelHead $traininglevelhead)
    {
        $traininglevelhead->delete();
        return $this->noContent();
    }
}
